package com.example.basic.core.result;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

/**
 * 统一API响应结果封装
 */
@ApiModel(value = "响应实体")
public class Result<T> implements Serializable  {
    /**
	 * 
	 */
	private static final long serialVersionUID = 3913566023103012448L;

	@JSONField(ordinal = 1)
    @ApiModelProperty(value = "响应编码")
	private int code;

	@JSONField(ordinal = 2)
    @ApiModelProperty(value = "响应消息")
    private String message;

	@JSONField(ordinal = 3)
    @ApiModelProperty(value = "响应对象")
    private T data;

    public Result<T> setCode(ResultCode resultCode) {
        this.code = resultCode.code;
        return this;
    }

    public int getCode() {
        return code;
    }

    public Result<T> setCode(int code) {
        this.code = code;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public Result<T> setMessage(String message) {
        this.message = message;
        return this;
    }

    public T getData() {
        return data;
    }

    public Result<T> setData(T data) {
        this.data = data;
        return this;
    }
    
	public Result(T data) {
		super();
		this.data = data;
	}

	public Result() {
		super();
		this.data = null;
	}
	
    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}
